package com.my.coolq.strategy.event.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.my.biz.service.IGroupInfoService;
import com.my.coolq.strategy.ReceiveMessagesHandleStrategy;
import com.my.coolq.strategy.event.model.GroupMemberIncreaseEvent;
import com.my.util.MapUtils;
/**
 * 群人数减少
 * @author ch
 *
 */
@Component
public class GroupMemberIncreaseEventHandleStrategy implements ReceiveMessagesHandleStrategy{

	private static final Logger LOGGER = LoggerFactory.getLogger(GroupMemberIncreaseEventHandleStrategy.class);
	
	private static final String REQUEST_TYPE="event_group_increase";
	
	private static final String INVITE="invite";
	
	@Autowired
	private IGroupInfoService groupInfoService;
	
	@Override
	public String getPostType() {
		return REQUEST_TYPE;
	}

	@Override
	public Object handle(Map<String, Object> params) {
		try {
			GroupMemberIncreaseEvent event = MapUtils.toObject(GroupMemberIncreaseEvent.class, params);
			LOGGER.info("group event={}",event);
			
			if(INVITE.equals(event.getSub_type()) && groupInfoService.isInviteBotAddGroup(event.getUser_id(),event.getGroup_id())){
				groupInfoService.getGroupAndGroupMemberInfo(event.getGroup_id());				
			}	
		}
		catch (Exception e) {
		}
		return null;
	}

}
